package Game;

public class Army {
    private Weapon[] w;
    private int Wnum=0;
    public Army(int max){
        w = new Weapon[max];//动态初始化
    }
    public void addWeapon(Weapon wa){
        w[Wnum]=wa;

        if (Wnum<w.length){
            Wnum++;
        }else {
            System.out.println("武器数量已达到最大");
        }
    }
    public void attackAll(){
        for (Weapon wa: w) {
            if (wa!=null){
                wa.attack();
            }
        }
    }
    public void moveAll(){
//        让可移动的武器移动
        for (Weapon wa: w) {
            if (wa!=null && wa instanceof Mobile){
                ((Mobile) wa).mobile();
            }
        }
    }
}
